<!DOCTYPE html>
<html>
<head>
    <meta content="text/html" charset="UTF-8">
    <title>微信管理平台</title>
    <link rel="stylesheet" type="text/css" href="css/themes/default/easyui.css">
    <link rel="stylesheet" href="css/themes/icon.css"/>
    <link rel="stylesheet" href="css/themes/color.css"/>
    <link rel="stylesheet" type="text/css" href="css/mycss.css"/>
    <link rel="stylesheet" type="text/css" href="css/themes/portal.css"/>
    <script type="text/javascript" src="js/jquery-2.1.1.min.js"></script>
    <script type="text/javascript" src="js/jquery.easyui.min.js"></script>
</head>
<body>
<div class="easyui-layout" fit="true">
    <div data-options="region:'center',split:true,border:false">
        <table id="weixin_user_datagird"></table>
    </div>
</div>

<div style="display: none">
</div>
<script type="text/javascript">
    var $=$||{};
    var $weixin_user_datagird=$('#weixin_user_datagird');
    $weixin_user_datagird.datagrid({
        url:'data/user.json',
        edititem:[],
        pagination:true,
        singleSelect:true,
        checkOnSelect:false,
        selectOnCheck:false,
        fit:true,
        columns: [
            [
                {field:'ck',checkbox:true},
                {field: 'id', title: 'UserId'},
                {field: 'username', title: '用户名'},
                {field: 'groupid', title: '用户组',width:180,
                    formatter:function(value,row){
                        return row.groupname;
                    },
                    editor:{
                        type:'combobox',
                        options:{
                            valueField:'groupid',
                            textField:'groupname',
                            method:'get',
                            url:'data/usergroup.json',
                            required:true,
                            loadFilter:function(data){
                                return data.rows;
                            }

                        }
                    }
                },
                {field: 'ctime', title: '创建时间', width: 80}
                /*{field: 'btn', title: '操作', formatter: function () {
                 return btn2;
                 }}*/
            ]
        ],
        onBeforeEdit:function(rowIndex){
            var a = $weixin_user_datagird.datagrid('options');
            console.log('开始编辑:'+rowIndex);
            a.edititem.push(rowIndex);
        },
        onDblClickRow:function(rowIndex){
            $weixin_user_datagird.datagrid('beginEdit',rowIndex);
        },
        toolbar:[
            {
                iconCls:'icon-add',
                text:'添加',
                handler:function(){
                    $weixin_user_datagird.datagrid('addRow',{
                                "username":"demo",
                                "ctime":new Date()
                    });
                }
            },
            {
                iconCls:'icon-save',
                text:'接受改变',
                handler:function(){
                    var aaa=$weixin_user_datagird.datagrid('options');
                    console.log(aaa);
                    $.each(aaa.edititem, function (i, n) {
                        var ed = $weixin_user_datagird.datagrid('getEditor', {index:n,field:'groupid'});
                        $weixin_user_datagird.datagrid('getRows')[n]['groupname'] = $(ed.target).combobox('getText');
                        $weixin_user_datagird.datagrid('endEdit', n);
                        aaa.edititem=[];
                    })
                }
            },
            {
                iconCls:'icon-save',
                text:'保存',
                handler:function(){
                    var rows=$weixin_user_datagird.datagrid('getChanges');
                    console.log(rows);
                }
            },
            {
                iconCls:'icon-cancel',
                text:'取消更改',
                handler:function(){
                    $weixin_user_datagird.datagrid('rejectChanges');
                }
            },
            {
                iconCls:'icon-remove',
                text:'删除',
                handler:function(){
                    var rows=$weixin_user_datagird.datagrid('getChecked');
                    $.messager.confirm('确认','您确认想要删除'+rows.length+'记录吗？',function(r){
                        if (r){
                            alert('确认删除');
                        }
                    });

                }
            },
            {
                iconCls:'icon-reload',
                text:'重新载入'
            },
            {
                id:'search',
                text:'搜索',
                iconCls:'icon-search'
            }
        ]
    });
</script>
</body>
<script type="text/javascript" src="js/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="js/jquery.easyui.min.js"></script>
<script type="text/javascript" src="js/jquery.portal.js"></script>
<script type="text/javascript" src="js/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="js/init.js"></script>
<script type="text/javascript" src="js/jquery.edatagrid.js"></script>
</html>